package view.desktop;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

import view.CadastroMae;
import view.windowBehavior.AcrylLookAndFeelBehavior;
import view.windowBehavior.McWinLookAndFeelBehavior;
import view.windowBehavior.WindowBehavior;

public class Desktop extends CadastroMae implements ActionListener {

	private JLabel lbEscolha;

	private JTextField txLogin;
	private JPasswordField password;

	private JButton btOk;
	private JButton btCancelar;

	private JPanel painelEsquerdo;
	private JPanel painelCentro;
	private JPanel painelSul;

	private WindowBehavior windowBehavior;

	public Desktop(ActionListener controler) {
		super("Visual", 500, 500, controler);
	}

	@Override
	public void exibir() {
		setVisible(true);
	}

	@Override
	public void fechar() {
		dispose();
	}

	@Override
	protected void init() {
		super.init();
		windowBehavior = new McWinLookAndFeelBehavior();

		getPainelForm().setBorder(new TitledBorder(getTitle()));

		lbEscolha = new JLabel("Escolha o Thema desejado:");

		txLogin = new JTextField(20);
		password = new JPasswordField(20);

		this.btOk = new JButton("Entrar");
		this.btOk.addActionListener(this);
		this.btOk.setActionCommand("entrar");

		btCancelar = new JButton("Cancelar");
		btCancelar.addActionListener(this);
		btCancelar.setActionCommand("cancelar");

		painelEsquerdo = new JPanel();
		painelCentro = new JPanel();
		painelSul = new JPanel();

	}

	@Override
	protected void setupLayout() {
		super.setupLayout();
		this.getPainelForm().setLayout(new BorderLayout());
		this.getPainelBotoes().setVisible(false);
		painelEsquerdo.setLayout(new GridLayout(2, 1, 1, 1));
		painelCentro.setLayout(new GridLayout(2, 1, 1, 1));
		painelSul.setLayout(new FlowLayout());
	}

	@Override
	protected void setupComponentes() {
		super.setupComponentes();

		JPanel aux1 = new JPanel();
		JPanel aux2 = new JPanel();
		JPanel aux3 = new JPanel();
		JPanel aux4 = new JPanel();

		aux1.setLayout(new FlowLayout());
		aux2.setLayout(new FlowLayout());
		aux3.setLayout(new FlowLayout());
		aux4.setLayout(new FlowLayout());

		aux1.add(lbEscolha);
		aux3.add(txLogin);
		aux4.add(password);

		painelEsquerdo.add(aux1);
		painelEsquerdo.add(aux2);

		painelCentro.add(aux3);
		painelCentro.add(aux4);

		painelSul.add(btOk);
		painelSul.add(btCancelar);

		getPainelForm().add(painelEsquerdo, BorderLayout.WEST);
		getPainelForm().add(painelCentro, BorderLayout.CENTER);
		getPainelForm().add(painelSul, BorderLayout.SOUTH);
	}

	public WindowBehavior getWindowBehavior() {
		return windowBehavior;
	}

	public void setWindowBehavior(WindowBehavior windowBehavior) {
		this.windowBehavior = windowBehavior;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == btCancelar){
			this.fechar();
		}
		if (e.getSource() == btOk){
			new AcrylLookAndFeelBehavior();
		}
	}

}
